//Home goals
var goals_home_id = new Array(0);
var goals_home_minute = new Array(0);
var goals_home_player = new Array(0);
function addHomeGoal(element) {
    goals_home_id.push(goals_home_id.length);
    goals_home_minute.push("");
    goals_home_player.push("");
    displayHomeGoals(element);
}
function deleteHomeGoal(element) {
    if (goals_home_id.length > 0) {
        goals_home_id.pop();
        goals_home_minute.pop();
        goals_home_player.pop();
    }
    displayHomeGoals(element);
}
function saveHomeGoalMinute(intId,strValue) {
    goals_home_minute[intId]=strValue;
}
function saveHomeGoalPlayer(intId,strValue) {
    goals_home_player[intId]=strValue;
}
function createHomeGoal(element, id, minute, player) {
    return "<input type='text' onChange='javascript:saveHomeGoalMinute("+ id +",this.value)' value='"+ minute +"' name='"+element+"_minute_"+id+"' size='1'> | <input type='text' onChange='javascript:saveHomeGoalPlayer("+ id +",this.value)' value='"+ player +"' name='"+element+"_player_"+id+"'><br/>";
}
function displayHomeGoals(element) {
    if (goals_home_id.length <= 0) {
        document.getElementById(element).innerHTML="";
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    } else {
        document.getElementById(element).innerHTML="Minute | Player<br/>";
        for (intI=0;intI<goals_home_id.length;intI++) {
            document.getElementById(element).innerHTML+=createHomeGoal(element, goals_home_id[intI], goals_home_minute[intI], goals_home_player[intI]);
        }
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    }
}

//Guests goals
var goals_guests_id = new Array(0);
var goals_guests_minute = new Array(0);
var goals_guests_player = new Array(0);
function addGuestsGoal(element) {
    goals_guests_id.push(goals_guests_id.length);
    goals_guests_minute.push("");
    goals_guests_player.push("");
    displayGuestsGoals(element);
}
function deleteGuestsGoal(element) {
    if (goals_guests_id.length > 0) {
        goals_guests_id.pop();
        goals_guests_minute.pop();
        goals_guests_player.pop();
    }
    displayGuestsGoals(element);
}
function saveGuestsGoalMinute(intId,strValue) {
    goals_guests_minute[intId]=strValue;
}
function saveGuestsGoalPlayer(intId,strValue) {
    goals_guests_player[intId]=strValue;
}
function createGuestsGoal(element, id, minute, player) {
    return "<input type='text' onChange='javascript:saveGuestsGoalMinute("+ id +",this.value)' value='"+ minute +"' name='"+element+"_minute_"+id+"' size='1'> | <input type='text' onChange='javascript:saveGuestsGoalPlayer("+ id +",this.value)' value='"+ player +"' name='"+element+"_player_"+id+"'><br/>";
}
function displayGuestsGoals(element) {
    if (goals_guests_id.length <= 0) {
        document.getElementById(element).innerHTML="";
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    } else {
        document.getElementById(element).innerHTML="Minute | Player<br/>";
        for (intI=0;intI<goals_guests_id.length;intI++) {
            document.getElementById(element).innerHTML+=createGuestsGoal(element, goals_guests_id[intI], goals_guests_minute[intI], goals_guests_player[intI]);
        }
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    }
}

//Home cards
var cards_home_id = new Array(0);
var cards_home_minute = new Array(0);
var cards_home_type = new Array(0);
var cards_home_player = new Array(0);
function addHomeCard(element) {
    cards_home_id.push(cards_home_id.length);
    cards_home_minute.push("");
    cards_home_type.push("");
    cards_home_player.push("");
    displayHomeCards(element);
}
function deleteHomeCard(element) {
    if (cards_home_id.length > 0) {
        cards_home_id.pop();
        cards_home_minute.pop();
        cards_home_type.pop();
        cards_home_player.pop();
    }
    displayHomeCards(element);
}
function saveHomeCardMinute(intId,strValue) {
    cards_home_minute[intId]=strValue;
}
function saveHomeCardType(intId,strValue) {
    cards_home_type[intId]=strValue;
}
function saveHomeCardPlayer(intId,strValue) {
    cards_home_player[intId]=strValue;
}
function createHomeCard(element, id, minute, type, player) {
    return "<input type='text' onChange='javascript:saveHomeCardMinute("+ id +",this.value)' value='"+ minute +"' name='"+element+"_minute_"+id+"' size='1'> | <input type='text' onChange='javascript:saveHomeCardType("+ id +",this.value)' value='"+ type +"' name='"+element+"_type_"+id+"' size='3'> | <input type='text' onChange='javascript:saveHomeCardPlayer("+ id +",this.value)' value='"+ player +"' name='"+element+"_player_"+id+"'><br/>";
}
function displayHomeCards(element) {
    if (cards_home_id.length <= 0) {
        document.getElementById(element).innerHTML="";
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    } else {
        document.getElementById(element).innerHTML="Minute | Type | Player<br/>";
        for (intI=0;intI<cards_home_id.length;intI++) {
            document.getElementById(element).innerHTML+=createHomeCard(element, cards_home_id[intI], cards_home_minute[intI], cards_home_type[intI], cards_home_player[intI]);
        }
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    }
}

//Guests cards
var cards_guests_id = new Array(0);
var cards_guests_minute = new Array(0);
var cards_guests_type = new Array(0);
var cards_guests_player = new Array(0);
function addGuestsCard(element) {
    cards_guests_id.push(cards_guests_id.length);
    cards_guests_minute.push("");
    cards_guests_type.push("");
    cards_guests_player.push("");
    displayGuestsCards(element);
}
function deleteGuestsCard(element) {
    if (cards_guests_id.length > 0) {
        cards_guests_id.pop();
        cards_guests_minute.pop();
        cards_guests_type.pop();
        cards_guests_player.pop();
    }
    displayGuestsCards(element);
}
function saveGuestsCardMinute(intId,strValue) {
    cards_guests_minute[intId]=strValue;
}
function saveGuestsCardType(intId,strValue) {
    cards_guests_type[intId]=strValue;
}
function saveGuestsCardPlayer(intId,strValue) {
    cards_guests_player[intId]=strValue;
}
function createGuestsCard(element, id, minute, type, player) {
    return "<input type='text' onChange='javascript:saveGuestsCardMinute("+ id +",this.value)' value='"+ minute +"' name='"+element+"_minute_"+id+"' size='1'> | <input type='text' onChange='javascript:saveGuestsCardType("+ id +",this.value)' value='"+ type +"' name='"+element+"_type_"+id+"' size='3'> | <input type='text' onChange='javascript:saveGuestsCardPlayer("+ id +",this.value)' value='"+ player +"' name='"+element+"_player_"+id+"'><br/>";
}
function displayGuestsCards(element) {
    if (cards_guests_id.length <= 0) {
        document.getElementById(element).innerHTML="";
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    } else {
        document.getElementById(element).innerHTML="Minute | Type | Player<br/>";
        for (intI=0;intI<cards_guests_id.length;intI++) {
            document.getElementById(element).innerHTML+=createGuestsCard(element, cards_guests_id[intI], cards_guests_minute[intI], cards_guests_type[intI], cards_guests_player[intI]);
        }
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    }
}

//Home changes
var changes_home_id = new Array(0);
var changes_home_minute = new Array(0);
var changes_home_in = new Array(0);
var changes_home_out = new Array(0);
function addHomeChange(element) {
    changes_home_id.push(changes_home_id.length);
    changes_home_minute.push("");
    changes_home_in.push("");
    changes_home_out.push("");
    displayHomeChanges(element);
}
function deleteHomeChange(element) {
    if (changes_home_id.length > 0) {
        changes_home_id.pop();
        changes_home_minute.pop();
        changes_home_in.pop();
        changes_home_out.pop();
    }
    displayHomeChanges(element);
}
function saveHomeChangeMinute(intId,strValue) {
    changes_home_minute[intId]=strValue;
}
function saveHomeChangeIn(intId,strValue) {
    changes_home_in[intId]=strValue;
}
function saveHomeChangeOut(intId,strValue) {
    changes_home_out[intId]=strValue;
}
function createHomeChange(element, id, minute, pin, out) {
    return "<input type='text' onChange='javascript:saveHomeChangeMinute("+ id +",this.value)' value='"+ minute +"' name='"+element+"_minute_"+id+"' size='1'> | <input type='text' onChange='javascript:saveHomeChangeIn("+ id +",this.value)' value='"+ pin +"' name='"+element+"_in_"+id+"'> | <input type='text' onChange='javascript:saveHomeChangeOut("+ id +",this.value)' value='"+ out +"' name='"+element+"_out_"+id+"'><br/>";
}
function displayHomeChanges(element) {
    if (changes_home_id.length <= 0) {
        document.getElementById(element).innerHTML="";
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    } else {
        document.getElementById(element).innerHTML="Minute | In | Out<br/>";
        for (intI=0;intI<changes_home_id.length;intI++) {
            document.getElementById(element).innerHTML+=createHomeChange(element, changes_home_id[intI], changes_home_minute[intI], changes_home_in[intI], changes_home_out[intI]);
        }
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    }
}

//Guests changes
var changes_guests_id = new Array(0);
var changes_guests_minute = new Array(0);
var changes_guests_in = new Array(0);
var changes_guests_out = new Array(0);
function addGuestsChange(element) {
    changes_guests_id.push(changes_guests_id.length);
    changes_guests_minute.push("");
    changes_guests_in.push("");
    changes_guests_out.push("");
    displayGuestsChanges(element);
}
function deleteGuestsChange(element) {
    if (changes_guests_id.length > 0) {
        changes_guests_id.pop();
        changes_guests_minute.pop();
        changes_guests_in.pop();
        changes_guests_out.pop();
    }
    displayGuestsChanges(element);
}
function saveGuestsChangeMinute(intId,strValue) {
    changes_guests_minute[intId]=strValue;
}
function saveGuestsChangeIn(intId,strValue) {
    changes_guests_in[intId]=strValue;
}
function saveGuestsChangeOut(intId,strValue) {
    changes_guests_out[intId]=strValue;
}
function createGuestsChange(element, id, minute, pin, out) {
    return "<input type='text' onChange='javascript:saveGuestsChangeMinute("+ id +",this.value)' value='"+ minute +"' name='"+element+"_minute_"+id+"' size='1'> | <input type='text' onChange='javascript:saveGuestsChangeIn("+ id +",this.value)' value='"+ pin +"' name='"+element+"_in_"+id+"'> | <input type='text' onChange='javascript:saveGuestsChangeOut("+ id +",this.value)' value='"+ out +"' name='"+element+"_out_"+id+"'><br/>";
}
function displayGuestsChanges(element) {
    if (changes_guests_id.length <= 0) {
        document.getElementById(element).innerHTML="";
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    } else {
        document.getElementById(element).innerHTML="Minute | In | Out<br/>";
        for (intI=0;intI<changes_guests_id.length;intI++) {
            document.getElementById(element).innerHTML+=createGuestsChange(element, changes_guests_id[intI], changes_guests_minute[intI], changes_guests_in[intI], changes_guests_out[intI]);
        }
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    }
}

//Home players
var players_home_id = new Array(0);
var players_home_player = new Array(0);
function addHomePlayer(element) {
    players_home_id.push(players_home_id.length);
    players_home_player.push("");
    displayHomePlayers(element);
}
function deleteHomePlayer(element) {
    if (players_home_id.length > 0) {
        players_home_id.pop();
        players_home_player.pop();
    }
    displayHomePlayers(element);
}
function saveHomePlayer(intId,strValue) {
    players_home_player[intId]=strValue;
}
function createHomePlayer(element, id, player) {
    return "<input type='text' onChange='javascript:saveHomePlayer("+ id +",this.value)' value='"+ player +"' name='"+element+"_player_"+id+"'><br/>";
}
function displayHomePlayers(element) {
    if (players_home_id.length <= 0) {
        document.getElementById(element).innerHTML="";
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    } else {
        document.getElementById(element).innerHTML="Player name<br/>";
        for (intI=0;intI<players_home_id.length;intI++) {
            document.getElementById(element).innerHTML+=createHomePlayer(element, players_home_id[intI], players_home_player[intI]);
        }
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    }
}

//Guest players
var players_guests_id = new Array(0);
var players_guests_player = new Array(0);
function addGuestsPlayer(element) {
    players_guests_id.push(players_guests_id.length);
    players_guests_player.push("");
    displayGuestsPlayers(element);
}
function deleteGuestsPlayer(element) {
    if (players_guests_id.length > 0) {
        players_guests_id.pop();
        players_guests_player.pop();
    }
    displayGuestsPlayers(element);
}
function saveGuestsPlayer(intId,strValue) {
    players_guests_player[intId]=strValue;
}
function createGuestsPlayer(element, id, player) {
    return "<input type='text' onChange='javascript:saveGuestsPlayer("+ id +",this.value)' value='"+ player +"' name='"+element+"_player_"+id+"'><br/>";
}
function displayGuestsPlayers(element) {
    if (players_guests_id.length <= 0) {
        document.getElementById(element).innerHTML="";
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    } else {
        document.getElementById(element).innerHTML="Player name<br/>";
        for (intI=0;intI<players_guests_id.length;intI++) {
            document.getElementById(element).innerHTML+=createGuestsPlayer(element, players_guests_id[intI], players_guests_player[intI]);
        }
        document.getElementById(element).innerHTML+="<input type='hidden' name='"+element+"_num' value='"+intI+"'>";
    }
}

//on page load
function loadVars() {
    for (intI=0;intI<document.getElementsByName('goals_home_num')[0].value;intI++) {
        goals_home_id.push(intI);
        goals_home_minute.push(document.getElementsByName('goals_home_minute_'+intI)[0].value);
        goals_home_player.push(document.getElementsByName('goals_home_player_'+intI)[0].value);
    }
    for (intI=0;intI<document.getElementsByName('goals_guests_num')[0].value;intI++) {
        goals_guests_id.push(intI);
        goals_guests_minute.push(document.getElementsByName('goals_guests_minute_'+intI)[0].value);
        goals_guests_player.push(document.getElementsByName('goals_guests_player_'+intI)[0].value);
    }
    for (intI=0;intI<document.getElementsByName('cards_home_num')[0].value;intI++) {
        cards_home_id.push(intI);
        cards_home_minute.push(document.getElementsByName('cards_home_minute_'+intI)[0].value);
        cards_home_type.push(document.getElementsByName('cards_home_type_'+intI)[0].value);
        cards_home_player.push(document.getElementsByName('cards_home_player_'+intI)[0].value);
    }
    for (intI=0;intI<document.getElementsByName('cards_guests_num')[0].value;intI++) {
        cards_guests_id.push(intI);
        cards_guests_minute.push(document.getElementsByName('cards_guests_minute_'+intI)[0].value);
        cards_guests_type.push(document.getElementsByName('cards_guests_type_'+intI)[0].value);
        cards_guests_player.push(document.getElementsByName('cards_guests_player_'+intI)[0].value);
    }
    for (intI=0;intI<document.getElementsByName('changes_home_num')[0].value;intI++) {
        changes_home_id.push(intI);
        changes_home_minute.push(document.getElementsByName('changes_home_minute_'+intI)[0].value);
        changes_home_in.push(document.getElementsByName('changes_home_in_'+intI)[0].value);
        changes_home_out.push(document.getElementsByName('changes_home_out_'+intI)[0].value);
    }
    for (intI=0;intI<document.getElementsByName('changes_guests_num')[0].value;intI++) {
        changes_guests_id.push(intI);
        changes_guests_minute.push(document.getElementsByName('changes_guests_minute_'+intI)[0].value);
        changes_guests_in.push(document.getElementsByName('changes_guests_in_'+intI)[0].value);
        changes_guests_out.push(document.getElementsByName('changes_guests_out_'+intI)[0].value);
    }
    for (intI=0;intI<document.getElementsByName('players_home_num')[0].value;intI++) {
        players_home_id.push(intI);
        players_home_player.push(document.getElementsByName('players_home_player_'+intI)[0].value);
    }
    for (intI=0;intI<document.getElementsByName('players_guests_num')[0].value;intI++) {
        players_guests_id.push(intI);
        players_guests_player.push(document.getElementsByName('players_guests_player_'+intI)[0].value);
    }
}
